package com.spica.platform.base.exception.errorcode;

import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

public enum AlgorithmRtnCodEnum implements IErrorCode {
    UN_KNOWN_ALGORITHM_ERROR("BASE_ALGORITHM_00000", "未知加解密异常"),
    REQUEST_BODY_DECRYPT_ERROR("BASE_ALGORITHM_00001", "解密失败，加密值不合法!"),
    REQUEST_DECRYPT_ERROR("BASE_ALGORITHM_00002", "请求数据解密失败!"),
    RESPONSE_BODY_ENCRYPT_ERROR("BASE_ALGORITHM_00003", "加密失败，加密值不合法!"),
    RESPONSE_BODY_ENCRYPT_FAIL_ERROR("BASE_ALGORITHM_00004", "响应数据加密失败！"),
    ENCRYPT_PASSWORD_FAIL_ERROR("BASE_ENCRYPT.PASSWORD_00005", "密码加密失败!"),
    ENCRYPT_PASSWORD_FALSIFIED("BASE_ENCRYPT.PASSWORD_00006", "用户存储密码已被篡改!"),
    ;
    private String rtnCod;
    private String rtnMsg;

    AlgorithmRtnCodEnum(String rtnCod, String rtnMsg) {
        this.rtnCod = rtnCod;
        this.rtnMsg = rtnMsg;
    };

    @Override
    public String getRtnMessage() {
        return this.rtnMsg;
    }

    @Override
    public String getRtnCode() {
        return this.rtnCod;
    }

    @Override
    public IErrorCode getInstanceByErrorCode(String errorCode) {
        return Arrays.stream(AlgorithmRtnCodEnum.values())
                .filter(algorithmRtnCodEnum -> StringUtil.equals(algorithmRtnCodEnum.rtnCod, errorCode))
                .findFirst().orElse(AlgorithmRtnCodEnum.UN_KNOWN_ALGORITHM_ERROR);
    }
}